﻿@model IEnumerable<Licence__WCG.Models.Licence>

@{
    ViewBag.Title = "主页";
}

<h2>证书信息列表</h2>

<p>
    @Html.ActionLink("添加", "Create")
</p>
<form method="get" class="form-inline text-center">
    证照名称：<input type="text" name="Name" class="form-control" />
    是否需要年审：@Html.DropDownList("IsReview", ViewBag.isReviewList as SelectList, new { @class = "form-control" })
    状态：@Html.DropDownList("State", ViewBag.stateList as SelectList, new { @class = "form-control" })
    <input type="submit" value="查询" class="btn btn-default" />
    <a href="@Url.Content("~/Home/Create")" class="btn btn-default">添加</a>
</form>
<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IssueDate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.VaildDate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.IsReview)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.ReviewDate)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.State)
        </th>
        <th></th>
    </tr>

    @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.IssueDate)
            </td>
            @if (item.VaildDate == null)
            {
                <td>
                    永久
                </td>
            }
            else
            {
                <td>
                    @Html.DisplayFor(modelItem => item.VaildDate)
                </td>
            }

            <td>
                @{string IsReviewStr = item.IsReview == true ? "是" : "否"; }
                @IsReviewStr
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.ReviewDate)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.State)
                
                @if (item.State == "借出" && item.LendUserID!=null)
                {
                    <span>(  @Html.DisplayFor(modelItem => item.UserInfo.UserName)  )</span>
                    string id = Session["ID"].ToString();
                    if (item.LendUserID.ToString() == id)
                    {
                        <a href="#" data-edit2="@item.ID">点击归还</a>
                    }
                }
            </td>
            <td>
            </td>
            <td>
                <a href="#" data-delete="@item.ID">删除</a>
                @if (item.State != "借出")
                {
                    <a href="#" data-edit="@item.ID">借出</a>
                }
            </td>
        </tr>
    }

</table>
@section Scripts {
    <script type="text/javascript">
       $(function () {
           $("a[data-delete]").click(function () {
                var $this = $(this);
               var id = $this.attr("data-delete");
                if (!confirm("你确定要删除吗？")) {
                    return;
                }
                $.post("@Url.Content("~/Home/Delete")", { id: id }, function (res) {
                    if (res) {
                        //局部刷新（删除选中行）
                        $this.closest("tr").remove();
                        alert("删除成功");
                    }
                })
           })
           $("a[data-edit]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-edit");
                if (!confirm("你确定借出吗？")) {
                    return;
                }
                $.post("@Url.Content("~/Home/Edit")", { id: id }, function (res) {
                    if (res) {
                        location.reload();
                        alert("借出成功");
                    }
                })
           })
            $("a[data-edit2]").click(function () {
                var $this = $(this);
                var id = $this.attr("data-edit2");
            if (!confirm("你确定归还吗？")) {
                return;
            }
            $.post("@Url.Content("~/Home/Edit")", { id: id }, function (res) {
                if (res) {
                    location.reload();
                    alert("归还成功");
                }
            })
        })
        })


    </script>



}
